

define(['jquery', 'bootstrap', 'fast', 'form','vue'], function ($, undefined, Fast, Form,Vue) {

    var Controller = {
        index: function () {             
            const vm =new Vue({
                el: '#app',
                data:{
                    commondata:['wr','week','days','fa'],
                    wdgroud:['wd','wf'],
                    selectTabble:true,               
                    user:null,//用户信息
                    head:[], //头部导航
                    banner:[],//轮播图
                    searchQuery: '',//搜索框
                    suggestions: [],//搜索建议
                    showSuggestions: false,//是否显示建议列表
                    selectedIndex: -1,//当前选中的建议索引
                    currentCategory: 0,//当前选中的分类
                    expandedCategories: {},//展开的分类
                    currentTab:'all',//当前选中的tab
                    itemTab:0,
                    page:1,
                    list:[],
                    wdcate:[],//分类
                    sortBy: 'latest',
                    more:true,
                },
                created() {
                    that = this;
                    Fast.api.ajax({
                        url: "ajax/auth",
                        loading: false,
                        async:true,
                        success:function(result) {
                            if (result.code == 200) {
                                that.user = result.data;
                            }
                        }
                    });
                    Fast.api.ajax({
                        url: "ajax/getcate",
                        loading: false,
                        async:true,
                        success:function(result) {

                            if (result.code == 200) {
                               
                                that.head = result.data.head;
                            }
                        }
                    });
                    this.getData();
                    
                },
                mounted() {
                    if (this.$el.contains(this.$refs.loadNode)) {
                        this.$el.removeChild(this.$refs.loadNode);
                    }
                    // 点击页面其他地方时关闭建议列表
                    document.addEventListener('click', (e) => {
                        if (!e.target.closest('.search-box')) {
                            that.showSuggestions = false;
                        }
                    });
                   
                    window.addEventListener('scroll', this.handleScroll);
                },
                beforeDestroy() {
                  // 页面销毁前移除滚动事件监听
                  window.removeEventListener('scroll', this.handleScroll);
                },
                methods:{
                    showFlag(id){
                        Fast.api.open('/member/submit?c=flag&t=document&id='+id,'赠送锦旗',{
                            minmax: false,
                            shadeClose:false,
                            area:['300px','400px'],
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    showComment(id){
                        Fast.api.open('/member/submit?c=comment&t=document&id='+id,'我要评论',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    showFavorites(id){
                        Fast.api.ajax({
                            url: "member/submit",
                            loading: false,
                            async:true,
                            data:{t:'document',id:id,c:'fa'},
                            
                        });
                    },
                    showFollow(id){
                        Fast.api.ajax({
                            url: "member/submit",
                            loading: false,
                            async:true,
                            data:{t:'document',id:id,c:'fo'},
                            
                        });
                    },
                    handleScroll() {
                        const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
                        const windowHeight = window.innerHeight || document.documentElement.clientHeight;
                        const documentHeight = document.documentElement.scrollHeight;
                        if (scrollTop + windowHeight >= (documentHeight-30)) {
                            that.getData();
                        }
                    },
                    handle(url,isLogin){

                        if(isLogin && !this.user){
                            window.location.href = '/login';
                            return;
                        }
                        if(isLogin && this.user.level == 0){
                            Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleBuy();
                            });
                            return;
                        }
                        window.location.href = url;
                    },
                    handleDetail(item){
                        if(!this.user){
                            window.location.href = '/login';
                            return;
                        }
                        switch (item.type) {
                            case 'wd':
                                url = '/wdgroup/detail?id='+item.doc_id;
                                break;
                            case 'wf':
                                url = '/wfgroup/detail?id='+item.doc_id;
                                break;
                            case 'wp':
                                url = '/wpgroup/detail?id='+item.doc_id;
                                break;
                            case 'wr':
                                if(this.user.level == 0){
                                    Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                        Fast.api.close(index);
                                        that.handleBuy();
                                    });
                                    return;
                                }
                                url = '/resource/detail?id='+item.doc_id;
                                break;
                            case 'fa':
                                    url = '/favorites/detail?id='+item.doc_id;
                                    break;
                            case 'week':
                                url = '/week/detail?id='+item.doc_id;
                                break;
                            case 'days':
                                url = '/days/detail?id='+item.doc_id;
                                break;
                        }
                        window.location.href = url;
                    },
                    handCate(item){
                        if(!this.user){
                            window.location.href = '/login';
                            return;
                        }
                        if(this.user.level == 0){
                            Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleBuy();
                            });
                            return ;
                        }
                        if(item.user_level_id >0 && !this.user.group_id.includes(item.user_level_id)){
                            
                            Fast.api.layer.confirm('本小组为申请制,仅提交申请并审核通过的会员可加入', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleAudit(item.user_level_id);
                            });
                            return ;
                        }
                       
                        this.itemTab = item.id;
                        window.location.href = '/wdgroup?wdid='+item.id;
                    },
                    handleSort(sort) {
                        this.sortBy = sort;
                        this.handleShow();
                    }, 
                    handleBuy(){
                        Fast.api.open('/member/level','会员购买',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    handleAudit(level){
                        Fast.api.open('/member/audit?id='+level,'我要申请',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    handleShow() {
                        this.page = 1;
                        this.more = true;
                        this.getData();                       
                    },
                    handleCurrent(tab) {
                        this.currentTab = tab;
                        this.handleShow();
                    },
                    getData(){
                        let that = this;
                        if(that.more == false){
                            return;
                        }
                        if(that.page > 1){
                            if(!this.user){
                                window.location.href = '/login';
                                return;
                            }
                            if( this.user.level == 0){
                                Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                    Fast.api.close(index);
                                    that.handleBuy();
                                });
                                return ;
                            }
                        }
                        // 在这里处理日期变化后的逻辑
                        const form = {
                            
                            index:this.currentTab,
                            sort:this.sortBy,
                            user_id:user_id,
                            page:this.page
                        }
                        let page = this.page;
                        Fast.api.ajax({
                            url: 'member/index',
                            data: form,
                            async:true,
                            loading: false,
                            success:function(result) {
                                if (result.code == 200) {
                                   if(that.page == 1){
                                    that.list = result.data;
                                   }else{
                                    that.list.push(...result.data);
                                   }
                                   if(result.data.length <10){
                                    that.more = false;
                                   }
                                   that.page = page+1;
                                }
                                
                            }
                        });
                    },

                    selectSuggestion(item) {
                        this.searchQuery = item.name;
                        this.showSuggestions = false;
                        
                    },
                    submitSearch() {
                       this.handleShow();
                    },
                    handleSelect(){
                       this.selectTabble = !this.selectTabble;
                    }
                }
            });
    
        },
        submit: function(){
            $(document).on('click', '.flag', function() {
               nums =  $(this).data('nums');
               $('input[name="nums"]').val(nums);
               $(this).addClass('active').siblings().removeClass('active');
            });
            Form.api.bindevent($('form[role=form]'));
        },
        level:function(){
            const vm =new Vue({
                el: '#app',
                data:{
                    selectTabble:true,               
                    user:null,//用户信息
                    levelTab:0,//当前选中的tab
                    payTab:'alipay',
                    list:[],
                    timer:null,
                },
                created() {
                    that = this;
                    Fast.api.ajax({
                        url: "ajax/auth",
                        loading: false,
                        async:true,
                        success:function(result) {
                            if (result.code == 200) {
                                that.user = result.data;
                            }
                        }
                    });
                    this.getData();
                    
                },
                mounted() {
                    if (this.$el.contains(this.$refs.loadNode)) {
                        this.$el.removeChild(this.$refs.loadNode);
                    }
                },
                methods:{
                    handleBuyLevel(){
                        let that = this;
                        const form = {
                            level:this.levelTab,
                            pay:this.payTab,
                        }
                        Fast.api.ajax({
                            url: "member/level",
                            loading: false,
                            async:true,
                            data:form,
                            success:function(result) {
                                if (result.code == 1) {
                                    Fast.api.layer.open({
                                        type: 1, 
                                        title: result.data.order.data,
                                        content: `<div style="padding: 15px;diplay:flex;flex-direction:column;align-items: center;justify-content:center;">
                                            <img src="`+result.data.url+`" width="320px" height="320px">
                                            <div style="font-size:18px;font-weight:600;padding:10px;">请使用`+(result.data.order.type=='wechat'?`微信`:`支付宝`)+`扫码支付</div>
                                            <div style="font-size:16px;padding:10px;">订单金额:`+result.data.order.price+`</div>
                                            <div style="font-size:16px;padding:10px;">订单5分钟内有效</div>
                                        </div>`
                                      });
                                    that.timer = setTimeout(function(){
                                        that.getReturnData(result.data.order.out_trade_no);
                                    }, 1500);
                                }else{
                                    Fast.api.toastr.error(data.msg);
                                }
                            }
                        });
                    },
                    handleCurrent(tab) {
                        this.levelTab = tab;
                    },
                    handleTab(tab){
                        this.payTab = tab;
                    },
                    getData(){
                        let that = this;
                        Fast.api.ajax({
                            url: 'ajax/userlevel',
                            async:true,
                            loading: false,
                            success:function(result) {
                                if (result.code == 200) {
                                    that.list = result.data;
                                    that.levelTab = result.data[0].id;
                                }
                            }
                        });
                    },
                    getReturnData(out_trade_no){
                        let that = this;
                        clearTimeout(that.timer);
                        Fast.api.ajax({
                            url: "/index/payment/return",
                            loading: false,
                            async:true,
                            data:{out_trade_no:out_trade_no},
                            success:function(result) {
                                if (result.code == 1) {
                                        Fast.api.toastr.success('购买会员成功');
                                        parent.location.reload();
                                }else{
                                    that.timer = setTimeout(function(){
                                        that.getReturnData(out_trade_no);
                                    }, 1500); 
                                }
                            }
                        });
                    }
                }
            });
        },
        favorites:function(){
            const vm =new Vue({
                el: '#app',
                data:{
                    commondata:['wr','week','days','fa'],
                    wdgroud:['wd','wf'],
                    selectTabble:true,               
                    user:null,//用户信息
                    head:[], //头部导航
                    banner:[],//轮播图
                    searchQuery: '',//搜索框
                    suggestions: [],//搜索建议
                    showSuggestions: false,//是否显示建议列表
                    selectedIndex: -1,//当前选中的建议索引
                    currentCategory: 0,//当前选中的分类
                    expandedCategories: {},//展开的分类
                    currentTab:'all',//当前选中的tab
                    itemTab:0,
                    page:1,
                    list:[],
                    wdcate:[],//分类
                    sortBy: 'latest',
                    more:true,
                },
                created() {
                    that = this;
                    Fast.api.ajax({
                        url: "ajax/auth",
                        loading: false,
                        async:true,
                        success:function(result) {
                            if (result.code == 200) {
                                that.user = result.data;
                            }
                        }
                    });
                    Fast.api.ajax({
                        url: "ajax/getcate",
                        loading: false,
                        async:true,
                        success:function(result) {

                            if (result.code == 200) {
                               
                                that.head = result.data.head;
                            }
                        }
                    });
                    this.getData();
                    
                },
                mounted() {
                    if (this.$el.contains(this.$refs.loadNode)) {
                        this.$el.removeChild(this.$refs.loadNode);
                    }

                    window.addEventListener('scroll', this.handleScroll);
                },
                beforeDestroy() {
                  // 页面销毁前移除滚动事件监听
                  window.removeEventListener('scroll', this.handleScroll);
                },
                methods:{
                    showFlag(id){
                        Fast.api.open('/member/submit?c=flag&t=document&id='+id,'赠送锦旗',{
                            maxmin: false,
                            shadeClose:false,
                            area:['300px','400px'],
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    showComment(id){
                        Fast.api.open('/member/submit?c=comment&t=document&id='+id,'我要评论',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    showFavorites(id){
                        Fast.api.ajax({
                            url: "member/submit",
                            loading: false,
                            async:true,
                            data:{t:'document',id:id,c:'fa'},
                           
                        });
                    },
                    escFavorites(id){
                        Fast.api.ajax({
                            url: "member/esc",
                            loading: false,
                            async:true,
                            data:{t:'document',id:id,c:'fa'},
                            success:function(data) {
                                if (data.code == 1) {
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    showFollow(id){
                        Fast.api.ajax({
                            url: "member/submit",
                            loading: false,
                            async:true,
                            data:{t:'document',id:id,c:'fo'},
                            
                        });
                    },
                    handleScroll() {
                        const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
                        const windowHeight = window.innerHeight || document.documentElement.clientHeight;
                        const documentHeight = document.documentElement.scrollHeight;
                        if (scrollTop + windowHeight >= (documentHeight-30)) {
                            that.getData();
                        }
                    },
                    handle(url,isLogin){

                        if(isLogin && !this.user){
                            window.location.href = '/login';
                            return;
                        }
                        if(isLogin && this.user.level == 0){
                            Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleBuy();
                            });
                            return;
                        }
                        window.location.href = url;
                    },
                    handleDetail(item){
                        if(!this.user){
                            window.location.href = '/login';
                            return;
                        }
                        switch (item.type) {
                            case 'wd':
                                url = '/wdgroup/detail?id='+item.doc_id;
                                break;
                            case 'wf':
                                url = '/wfgroup/detail?id='+item.doc_id;
                                break;
                            case 'wp':
                                url = '/wpgroup/detail?id='+item.doc_id;
                                break;
                            case 'wr':
                                if(this.user.level == 0){
                                    Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                        Fast.api.close(index);
                                        that.handleBuy();
                                    });
                                    return;
                                }
                                url = '/resource/detail?id='+item.doc_id;
                                break;
                            case 'fa':
                                    url = '/favorites/detail?id='+item.doc_id;
                                    break;
                            case 'week':
                                url = '/week/detail?id='+item.doc_id;
                                break;
                            case 'days':
                                url = '/days/detail?id='+item.doc_id;
                                break;
                        }
                        window.location.href = url;
                    },
                    handCate(item){
                        if(!this.user){
                            window.location.href = '/login';
                            return;
                        }
                        if(this.user.level == 0){
                            Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleBuy();
                            });
                            return ;
                        }
                        if(item.user_level_id >0 && !this.user.group_id.includes(item.user_level_id)){
                            
                            Fast.api.layer.confirm('本小组为申请制,仅提交申请并审核通过的会员可加入', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleAudit(item.user_level_id);
                            });
                            return ;
                        }
                       
                        this.itemTab = item.id;
                        window.location.href = '/wdgroup?wdid='+item.id;
                    },
                    handleSort(sort) {
                        this.sortBy = sort;
                        this.handleShow();
                    }, 
                    handleBuy(){
                        Fast.api.open('/member/level','会员购买',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    handleAudit(level){
                        Fast.api.open('/member/audit?id='+level,'我要申请',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    handleAttention(id){
                        Fast.api.ajax({
                            url: "member/submit",
                            loading: false,
                            async:true,
                            data:{t:'wd',id:id,c:'at'},
                            success:function(data) 
                            {
                                if (data.code == 1) {
                                    Fast.api.toastr.success(data.msg);
                                }else{
                                    Fast.api.toastr.error(data.msg);
                                }
                            },
                            error:function(data) {
                                Fast.api.toastr.error(data.msg);
                            }
                        });
                    },
                    handleShow() {
                        this.page = 1;
                        this.more = true;
                        this.getData();                       
                    },
                    handleCurrent(tab) {
                        this.currentTab = tab;
                        this.handleShow();
                    },
                    getData(){
                        let that = this;
                        if(that.more == false){
                            return;
                        }
                        if(that.page > 1){
                            if(!this.user){
                                window.location.href = '/login';
                                return;
                            }
                            if( this.user.level == 0){
                                Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                    Fast.api.close(index);
                                    that.handleBuy();
                                });
                                return ;
                            }
                        }
                        // 在这里处理日期变化后的逻辑
                        const form = {
                            user_id:user_id,
                            page:this.page
                        }
                        let page = this.page;
                        Fast.api.ajax({
                            url: 'member/favorites',
                            data: form,
                            async:true,
                            loading: false,
                            success:function(result) {
                                if (result.code == 200) {
                                   if(that.page == 1){
                                    that.list = result.data;
                                   }else{
                                    that.list.push(...result.data);
                                   }
                                   if(result.data.length <10){
                                    that.more = false;
                                   }
                                   that.page = page+1;
                                }
                                
                            }
                        });
                    },

                    selectSuggestion(item) {
                        this.searchQuery = item.name;
                        this.showSuggestions = false;
                        
                    },
                    submitSearch() {
                       this.handleShow();
                    },
                    handleSelect(){
                       this.selectTabble = !this.selectTabble;
                    }
                }
            });
        }, 
        comments:function(){
            const vm =new Vue({
                el: '#app',
                data:{
                    commondata:['wr','week','days','fa'],
                    wdgroud:['wd','wf'],
                    selectTabble:true,               
                    user:null,//用户信息
                    head:[], //头部导航
                    banner:[],//轮播图
                    searchQuery: '',//搜索框
                    suggestions: [],//搜索建议
                    showSuggestions: false,//是否显示建议列表
                    selectedIndex: -1,//当前选中的建议索引
                    currentCategory: 0,//当前选中的分类
                    expandedCategories: {},//展开的分类
                    currentTab:'all',//当前选中的tab
                    itemTab:0,
                    page:1,
                    list:[],
                    wdcate:[],//分类
                    sortBy: 'latest',
                    more:true,
                },
                created() {
                    that = this;
                    Fast.api.ajax({
                        url: "ajax/auth",
                        loading: false,
                        async:true,
                        success:function(result) {
                            if (result.code == 200) {
                                that.user = result.data;
                            }
                        }
                    });
                    Fast.api.ajax({
                        url: "ajax/getcate",
                        loading: false,
                        async:true,
                        success:function(result) {

                            if (result.code == 200) {
                               
                                that.head = result.data.head;
                            }
                        }
                    });
                    this.getData();
                    
                },
                mounted() {
                    if (this.$el.contains(this.$refs.loadNode)) {
                        this.$el.removeChild(this.$refs.loadNode);
                    }

                    window.addEventListener('scroll', this.handleScroll);
                },
                beforeDestroy() {
                  // 页面销毁前移除滚动事件监听
                  window.removeEventListener('scroll', this.handleScroll);
                },
                methods:{
                    showFlag(id){
                        Fast.api.open('/member/submit?c=flag&t=document&id='+id,'赠送锦旗',{
                            maxmin: false,
                            shadeClose:false,
                            area:['300px','400px'],
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    showComment(id){
                        Fast.api.open('/member/submit?c=comment&t=document&id='+id,'我要评论',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    showFavorites(id){
                        Fast.api.ajax({
                            url: "member/submit",
                            loading: false,
                            async:true,
                            data:{t:'document',id:id,c:'fa'},
                           
                        });
                    },
                    escFavorites(id){
                        Fast.api.ajax({
                            url: "member/esc",
                            loading: false,
                            async:true,
                            data:{t:'document',id:id,c:'fa'},
                            success:function(data) {
                                if (data.code == 1) {
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    showFollow(id){
                        Fast.api.ajax({
                            url: "member/submit",
                            loading: false,
                            async:true,
                            data:{t:'document',id:id,c:'fo'},
                            
                        });
                    },
                    handleScroll() {
                        const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
                        const windowHeight = window.innerHeight || document.documentElement.clientHeight;
                        const documentHeight = document.documentElement.scrollHeight;
                        if (scrollTop + windowHeight >= (documentHeight-30)) {
                            that.getData();
                        }
                    },
                    handle(url,isLogin){

                        if(isLogin && !this.user){
                            window.location.href = '/login';
                            return;
                        }
                        if(isLogin && this.user.level == 0){
                            Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleBuy();
                            });
                            return;
                        }
                        window.location.href = url;
                    },
                    handleDetail(item){
                        if(!this.user){
                            window.location.href = '/login';
                            return;
                        }
                        switch (item.type) {
                            case 'wd':
                                url = '/wdgroup/detail?id='+item.doc_id;
                                break;
                            case 'wf':
                                url = '/wfgroup/detail?id='+item.doc_id;
                                break;
                            case 'wp':
                                url = '/wpgroup/detail?id='+item.doc_id;
                                break;
                            case 'wr':
                                if(this.user.level == 0){
                                    Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                        Fast.api.close(index);
                                        that.handleBuy();
                                    });
                                    return;
                                }
                                url = '/resource/detail?id='+item.doc_id;
                                break;
                            case 'fa':
                                    url = '/favorites/detail?id='+item.doc_id;
                                    break;
                            case 'week':
                                url = '/week/detail?id='+item.doc_id;
                                break;
                            case 'days':
                                url = '/days/detail?id='+item.doc_id;
                                break;
                        }
                        window.location.href = url;
                    },
                    handCate(item){
                        if(!this.user){
                            window.location.href = '/login';
                            return;
                        }
                        if(this.user.level == 0){
                            Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(){
                                that.handleBuy();
                            });
                            return ;
                        }
                        if(item.user_level_id >0 && !this.user.group_id.includes(item.user_level_id)){
                            
                            Fast.api.layer.confirm('本小组为申请制,仅提交申请并审核通过的会员可加入', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleAudit(item.user_level_id);
                            });
                            return ;
                        }
                       
                        this.itemTab = item.id;
                        window.location.href = '/wdgroup?wdid='+item.id;
                    },
                    handleSort(sort) {
                        this.sortBy = sort;
                        this.handleShow();
                    }, 
                    handleBuy(){
                        Fast.api.open('/member/level','会员购买',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    handleAudit(level){
                        Fast.api.open('/member/audit?id='+level,'我要申请',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    handleAttention(id){
                        Fast.api.ajax({
                            url: "member/submit",
                            loading: false,
                            async:true,
                            data:{t:'wd',id:id,c:'at'},
                            success:function(data) 
                            {
                                if (data.code == 1) {
                                    Fast.api.toastr.success(data.msg);
                                }else{
                                    Fast.api.toastr.error(data.msg);
                                }
                            },
                            error:function(data) {
                                Fast.api.toastr.error(data.msg);
                            }
                        });
                    },
                    handleShow() {
                        this.page = 1;
                        this.more = true;
                        this.getData();                       
                    },
                    handleCurrent(tab) {
                        this.currentTab = tab;
                        this.handleShow();
                    },
                    getData(){
                        let that = this;
                        if(that.more == false){
                            return;
                        }
                        if(that.page > 1){
                            if(!this.user){
                                window.location.href = '/login';
                                return;
                            }
                            if( this.user.level == 0){
                                Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                    Fast.api.close(index);
                                    that.handleBuy();
                                });
                                return ;
                            }
                        }
                        // 在这里处理日期变化后的逻辑
                        const form = {
                            user_id:user_id,
                            page:this.page
                        }
                        let page = this.page;
                        Fast.api.ajax({
                            url: 'member/comments',
                            data: form,
                            async:true,
                            loading: false,
                            success:function(result) {
                                if (result.code == 200) {
                                   if(that.page == 1){
                                    that.list = result.data;
                                   }else{
                                    that.list.push(...result.data);
                                   }
                                   if(result.data.length <10){
                                    that.more = false;
                                   }
                                   that.page = page+1;
                                }
                                
                            }
                        });
                    },

                    selectSuggestion(item) {
                        this.searchQuery = item.name;
                        this.showSuggestions = false;
                        
                    },
                    submitSearch() {
                       this.handleShow();
                    },
                    handleSelect(){
                       this.selectTabble = !this.selectTabble;
                    }
                }
            });
        },
        audit:function(){
            const vm =new Vue({
                el: '#app',
                data:{               
                    user:null,//用户信息
                    head:[], //头部导航
                    item:null,
                    typename:''
                },
                created() {
                    that = this;
                    Fast.api.ajax({
                        url: "ajax/auth",
                        loading: false,
                        async:true,
                        success:function(result) {
                            if (result.code == 200) {
                                that.user = result.data;
                            }
                        }
                    });
                    Fast.api.ajax({
                        url: "ajax/getcate",
                        loading: false,
                        async:true,
                        success:function(result) {

                            if (result.code == 200) {
                                
                                that.head = result.data.head;
                            }
                        }
                    });
                    
                },
                mounted() {
                    console.log(this.item);
                    if (this.$el.contains(this.$refs.loadNode)) {
                        this.$el.removeChild(this.$refs.loadNode);
                    }
                },
                methods:{
                    handle(url,isLogin){

                        if(isLogin && !this.user){
                            window.location.href = '/login';
                            return;
                        }
                        if(isLogin && this.user.level == 0){
                            Fast.api.layer.confirm('需要成为闻道会员可访问', {title:'提示',icon: 3}, function(index){
                                Fast.api.close(index);
                                that.handleBuy();
                            });
                            return;
                        }
                        window.location.href = url;
                    },
                    handleBuy(){
                        Fast.api.open('/member/level','会员购买',{
                            minmax: false,
                            shadeClose:false,
                            shade:0.3,
                            callback: function (data) {
                                if(data.code == 1){
                                    Fast.api.close();
                                    Fast.api.success(data.msg);
                                }else{
                                    Fast.api.error(data.msg);
                                }
                            }
                        });
                    },
                    handleSend(){
                        console.log(this.$refs.form);
                    },
                }
            });
            Form.api.bindevent($("form[role=form]"));
        }
    };        
    return Controller;
});
